/**
 * @author Ryan Milligan
 *
 * The CategoryNode class stores a single site category.
 */

package org.seaurchin.category;

import java.util.HashSet;
import java.util.Set;

class CategoryNode {
	private String name;
	private CategoryNode parent;
	private Set<CategoryNode> children;
	
	public CategoryNode() {
		this.name = null;
		this.parent = null;
		this.children = new HashSet<CategoryNode>();
	}
	
	public String getCategoryPath() {
		if(this.parent == null)
			return "";
		else
			return this.parent.getCategoryPath() + "/" + this.name;
	}
	
	public boolean hasChild(String childCategory) {
		for(CategoryNode category : children) {
			if(childCategory.equals(category.getName())) {
				return true;
			}
		}
		return false;
	}
	
	public void addChild(String childCategory) {
		CategoryNode child = new CategoryNode();
		child.setName(childCategory);
		child.setParent(this);
		this.children.add(child);
	}
	
	public CategoryNode getChild(String childCategory) {
		for(CategoryNode category : children) {
			if(childCategory.equals(category.getName())) {
				return category;
			}
		}
		return null;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public CategoryNode getParent() {
		return parent;
	}

	public void setParent(CategoryNode parent) {
		this.parent = parent;
	}

	public Set<CategoryNode> getChildren() {
		return children;
	}

	public void setChildren(Set<CategoryNode> children) {
		this.children = children;
	}

}
